<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:p="http://primefaces.org/ui"
                template="/template.xhtml">

    <ui:define name="title">
        <h:outputText value="#{bundle.TransaccionTitle}"/>
    </ui:define>
        
        <ui:define name="body">
            
            <h:form id="TransaccionCreateForm">
                
                <h:panelGrid columns="1" width="100%">           
                   
                            <p:panel id="panel1" header="Informacion de la transacción">
                                
                                <h:panelGrid columns="2" width="100%" >
                                    
                                    <p:outputLabel value="#{bundle.CreateTransaccionLabel_codigo}" for="codigo" />
                                    <p:inputText id="codigo" value="#{transaccionController.current.codigo}" 
                                                 title="#{bundle.CreateTransaccionTitle_codigo}" />
                                                     
                                    <p:outputLabel value="#{bundle.CreateTransaccionLabel_fecha}" for="fecha" />
                                    <p:calendar id="fecha" pattern="dd/MM/yyyy" 
                                                value="#{transaccionController.current.fecha}" 
                                                title="#{bundle.EditTransaccionTitle_fecha}" required="true" 
                                                requiredMessage="#{bundle.EditTransaccionRequiredMessage_fecha}" showOn="button"/>
                                      
                                    <p:outputLabel value="#{bundle.CreateTransaccionDetalleLabel_idSocio}" for="idSocio" />
                                    <p:selectOneMenu id="idSocio" value="#{transaccionController.current.idSocio}" required="true" 
                                                     requiredMessage="#{bundle.EditTransaccionDetalleRequiredMessage_idSocio}">
                                        <f:selectItem itemLabel="#{bundle.SelectOneMessage}"/>
                                        <f:selectItems value="#{socioController.items}"
                                                       var="idSocioItem"
                                                       itemValue="#{idSocioItem}"
                                                       itemLabel="#{idSocioItem.getNombreCompleto()}"
                                                       />
                                        <f:converter binding="#{socioConverter}"/>
                                    </p:selectOneMenu>
                                    
                                    <p:outputLabel rendered="false" value="#{bundle.CreateTransaccionLabel_totalMonto}" for="totalMonto" />
                                    <p:inputText rendered="false" id="totalMonto" value="#{transaccionController.current.totalMonto}" 
                                                 title="#{bundle.CreateTransaccionTitle_totalMonto}" required="true" 
                                                 requiredMessage="#{bundle.CreateTransaccionRequiredMessage_totalMonto}"/>
                                                     
                                    <p:outputLabel rendered="false" value="#{bundle.CreateTransaccionLabel_creationDate}" for="creationDate" />
                                    <p:calendar rendered="false" id="creationDate" pattern="dd/MM/yyyy HH:mm:ss" value="#{transaccionController.current.creationDate}" title="#{bundle.EditTransaccionTitle_creationDate}" required="true" requiredMessage="#{bundle.EditTransaccionRequiredMessage_creationDate}" showOn="button"/>
                                        
                                    <p:outputLabel rendered="false" value="#{bundle.CreateTransaccionLabel_createdBy}" for="createdBy" />
                                    <p:inputText rendered="false" id="createdBy" value="#{transaccionController.current.createdBy}" 
                                                 title="#{bundle.CreateTransaccionTitle_createdBy}" required="true" 
                                                 requiredMessage="#{bundle.CreateTransaccionRequiredMessage_createdBy}"/>
                                                     
                                    <p:outputLabel rendered="false" value="#{bundle.CreateTransaccionLabel_lastUpdateDate}" for="lastUpdateDate" />
                                    <p:calendar rendered="false" id="lastUpdateDate" pattern="dd/MM/yyyy HH:mm:ss" 
                                                value="#{transaccionController.current.lastUpdateDate}" 
                                                title="#{bundle.EditTransaccionTitle_lastUpdateDate}"  showOn="button"/>
                                                    
                                    <p:outputLabel rendered="false" value="#{bundle.CreateTransaccionLabel_lastUpdateBy}" for="lastUpdateBy" />
                                    <p:inputText rendered="false" id="lastUpdateBy" value="#{transaccionController.current.lastUpdateBy}" 
                                                 title="#{bundle.CreateTransaccionTitle_lastUpdateBy}" required="true" 
                                                 requiredMessage="#{bundle.CreateTransaccionRequiredMessage_lastUpdateBy}"/>
                                </h:panelGrid>
                                
                                <p:commandButton actionListener="#{transaccionController.createNew}" value="#{bundle.Save}" 
                                                 rendered="#{transaccionController.transCreada == false}" icon="ui-icon-disk"
                                                 update=":TransaccionCreateForm:panel1,:TransaccionDetalleCreateForm:panel2,:growl" />
                                
                                <p:commandButton value="#{bundle.Cancel}" update="TransaccionCreateForm" process="@this" 
                                                 icon="ui-icon-refresh" rendered="#{transaccionController.transCreada == false}">  
                                    <p:resetInput target="TransaccionCreateForm" />  
                                </p:commandButton>   
                                
                            </p:panel>
                    
                </h:panelGrid>
            </h:form>
            
            <h:form id="TransaccionDetalleCreateForm">
                
                <h:panelGrid columns="1" width="100%">
                
                            <p:panel id="panel2" header="Detalle de la transacción" >
                                
                                <h:panelGrid columns="4" width="100%" >
                                    
                                    <p:outputLabel value="#{bundle.CreateTransaccionDetalleLabel_cantidad}" for="cantidad" />
                                    <p:inputText id="cantidad" readonly="true" value="#{transaccionDetalleController.current.cantidad}" title="#{bundle.CreateTransaccionDetalleTitle_cantidad}" required="true" requiredMessage="#{bundle.CreateTransaccionDetalleRequiredMessage_cantidad}"/>
                                        
                                    <p:outputLabel value="#{bundle.CreateTransaccionDetalleLabel_monto}" for="monto" />
                                    <p:inputText id="monto" value="#{transaccionDetalleController.current.monto}" 
                                                 title="#{bundle.CreateTransaccionDetalleTitle_monto}" required="true" 
                                                 requiredMessage="#{bundle.CreateTransaccionDetalleRequiredMessage_monto}"
                                                 converterMessage="El monto debe ser un numero positivo en el rango entre 0.00 y 99999999.99"
                                                 validatorMessage="El rango de monto es entre 0.00 y 99999999.99" >
                                        <f:convertNumber maxFractionDigits="2" maxIntegerDigits="8" groupingUsed="true"
                                             type="number" locale="en" />
                                        <f:validateDoubleRange maximum="99999999.99" minimum="0.00"/>
                                    </p:inputText>
                                    
                                    <p:outputLabel value="#{bundle.CreateTransaccionDetalleLabel_fechaTransaccion}" for="fechaTransaccion" />
                                    <p:calendar id="fechaTransaccion" pattern="dd/MM/yyyy HH:mm:ss" 
                                                value="#{transaccionDetalleController.current.fechaTransaccion}" 
                                                title="#{bundle.EditTransaccionDetalleTitle_fechaTransaccion}" 
                                                required="true" requiredMessage="#{bundle.EditTransaccionDetalleRequiredMessage_fechaTransaccion}" 
                                                showOn="button"/>
                                        
                                    <p:outputLabel value="#{bundle.CreateTransaccionDetalleLabel_idUnidad}" for="idUnidad" />
                                    <p:selectOneMenu id="idUnidad" value="#{transaccionDetalleController.current.idUnidad}" 
                                                     required="true" requiredMessage="#{bundle.EditTransaccionDetalleRequiredMessage_idUnidad}">
                                        <f:selectItem itemLabel="#{bundle.SelectOneMessage}"/>
                                        <f:selectItems value="#{unidadController.items}"
                                                       var="idUnidadItem"
                                                       itemValue="#{idUnidadItem}"
                                                       itemLabel="#{idUnidadItem.codigo.toString()}" />
                                        <f:converter binding="#{unidadConverter}"/>
                                    </p:selectOneMenu>
                                        
                                    <p:outputLabel rendered="false" value="#{bundle.CreateTransaccionDetalleLabel_idTransaccion}" for="idTransaccion" />
                                    <p:selectOneMenu rendered="false" id="idTransaccion" value="#{transaccionDetalleController.current.idTransaccion}" 
                                                     required="true" requiredMessage="#{bundle.EditTransaccionDetalleRequiredMessage_idTransaccion}">
                                        <f:selectItem itemLabel="#{bundle.SelectOneMessage}"/>
                                        <f:selectItems value="#{transaccionController.items}"
                                                       var="idTransaccionItem"
                                                       itemValue="#{idTransaccionItem}"
                                                       itemLabel="#{idTransaccionItem.id.toString()}"
                                                       />
                                        <f:converter binding="#{transaccionConverter}"/>
                                    </p:selectOneMenu>
                                        
                                    <p:outputLabel value="#{bundle.CreateTransaccionDetalleLabel_idTipoPago}" for="idTipoPago" />
                                    <p:selectOneMenu id="idTipoPago" value="#{transaccionDetalleController.current.idTipoPago}" 
                                                     required="true" requiredMessage="#{bundle.EditTransaccionDetalleRequiredMessage_idTipoPago}">
                                        <f:selectItem itemLabel="#{bundle.SelectOneMessage}"/>
                                        <f:selectItems value="#{tipoPagoController.items}"
                                                       var="idTipoPagoItem"
                                                       itemValue="#{idTipoPagoItem}"
                                                       itemLabel="#{idTipoPagoItem.descripcion.toString()}"
                                                       />
                                        <f:converter binding="#{tipoPagoConverter}"/>
                                    </p:selectOneMenu>
                                        
                                    
                                </h:panelGrid>
                                <p:commandButton actionListener="#{transaccionDetalleController.createNew}" value="#{bundle.Save}" 
                                                 rendered="false"
                                                 update=":TransaccionCreateForm:panel2,:growl" />
                                
                                <p:commandButton value="Agregar Detalle" immediate="false" 
                                                 rendered="#{transaccionController.transCreada == true}"
                                                 actionListener="#{transaccionDetalleController.createNew}" icon="ui-icon-plus" 
                                                 update=":TransaccionDetalleCreateForm:panel2,:TransaccionDetalleCreateForm:display,:growl" />
                                                                
                                <p:commandButton value="#{bundle.Cancel}" update="TransaccionDetalleCreateForm" process="@this" 
                                                 icon="ui-icon-refresh" rendered="#{transaccionController.transCreada == true}">  
                                    <p:resetInput target="TransaccionDetalleCreateForm" />  
                                </p:commandButton>
                                
                            </p:panel>
                                        
                            <p:panel id="display"  header="Resultado" style="margin-top:10px;" >  

                                <h:dataTable id="transacciondet" value="#{transaccionDetalleController.detailList}" var="item" border="0" 
                                             cellpadding="2" cellspacing="0" rules="all" rowClasses="jsfcrud_odd_row,jsfcrud_even_row" 
                                             style="border:solid 1px; margin: auto" rendered="#{transaccionDetalleController.detalleCreado == true}">

                                    <h:column rendered="false" >
                                        <f:facet name="header">
                                            <h:outputText value="id &lt;br /&gt; id"/>
                                        </f:facet>
                                        <h:outputText value="#{item.codigo}"/>
                                    </h:column>
                                    <h:column>
                                        <f:facet name="header">
                                            <h:outputText value="#{bundle.ListTransaccionDetalleTitle_cantidad}"/>
                                        </f:facet>
                                        <h:outputText value="#{item.cantidad}"/>
                                    </h:column>
                                    <h:column >
                                        <f:facet name="header">
                                            <h:outputText value="#{bundle.ListTransaccionDetalleTitle_monto}" />
                                        </f:facet>
                                        <h:outputText value="#{item.monto}" >
                                            <f:convertNumber  maxFractionDigits="2" groupingUsed="true" locale="en" 
                                                                 currencySymbol="$" type="currency"/>
                                        </h:outputText>
                                    </h:column>
                                                                        
                                    <h:column >
                                        <f:facet name="header">
                                            <h:outputText value="#{bundle.ListTransaccionDetalleTitle_fechaTransaccion}"/>
                                        </f:facet>
                                        <h:outputText value="#{item.fechaTransaccion}">
                                            <f:convertDateTime pattern="dd/MM/yyyy HH:mm:ss" />
                                        </h:outputText>
                                    </h:column>
                                    <h:column >
                                        <f:facet name="header">
                                            <h:outputText value="#{bundle.ListTransaccionDetalleTitle_idUnidad}"/>
                                        </f:facet>
                                        <h:outputText value="#{item.idUnidad.codigo}"/>
                                    </h:column>
                                    <h:column rendered="false" >
                                        <f:facet name="header">
                                            <h:outputText value="#{bundle.ListTransaccionDetalleTitle_idTransaccion}"/>
                                        </f:facet>
                                        <h:outputText value="#{item.idTransaccion.id}"/>
                                    </h:column>
                                    <h:column >
                                        <f:facet name="header">
                                            <h:outputText value="#{bundle.ListTransaccionDetalleTitle_idTipoPago}"/>
                                        </f:facet>
                                        <h:outputText value="#{item.idTipoPago.descripcion}"/>
                                    </h:column>
                                                                             
                                    <h:column>
                                        <f:facet name="header">
                                            <h:outputText value="&nbsp;"/>
                                        </f:facet>

                                        <p:commandButton id="deleteButton" icon="ui-icon-trash" immediate="true" 
                                                         actionListener="#{transaccionDetalleController.removeItem(item)}"
                                                         update=":growl,:TransaccionDetalleCreateForm:display" />                                               
                                    </h:column>             

                                </h:dataTable>

                            </p:panel>
                                     
                </h:panelGrid>
                    
            </h:form>
                
        </ui:define>
            
    </ui:composition>
